using System;
namespace RpgServiceLib.Faction
{
	public class Faction
	{
		public virtual string DisplayNameOfFaction { get; set; }
		protected virtual FactionLevelNameCollection FactionLevelNameCollection {get;set;}
	
		public Faction (string displayName, FactionLevelNameCollection factionLevelCollection)
		{			
			this.DisplayNameOfFaction = displayName;
			FactionLevelNameCollection = factionLevelCollection;
		}
		
		public virtual FactionLevelName GetFactionLevelNameForLevel (int level)
		{
			FactionLevelName bestFaction = null;
			foreach (FactionLevelName factionLevelName in FactionLevelNameCollection) {
				Console.WriteLine("Level = " + level + " FLN = " 
				+ factionLevelName.NameOfFactionLevel + "/" + factionLevelName.LevelBegin + " " + (factionLevelName.LevelBegin <= level) + "/" + (factionLevelName.LevelBegin >= level));
				
				if (factionLevelName.LevelBegin <= level)
				{
					bestFaction = factionLevelName;
				}
				if (factionLevelName.LevelBegin >= level) {
					return bestFaction;
				}
			}				
			return bestFaction;
		}
	}
}

